<?php
/**
 * Fastapp.
 * 3/26/24
 * @Author deepsea
 * @Contact telegram:deepsea159
 */

namespace App\Fastapp\Api\Controller\Comm;

use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Api\Service\Comm\AppService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller('api/comm/app')]
class AppController extends ApiController
{
    #[Inject]
    public AppService $service;

    #[GetMapping('config')]
    public function config(): ResponseInterface
    {
        return $this->success($this->service->config());
    }

    #[GetMapping('settingConfig')]
    public function settingConfig(): ResponseInterface
    {
        $this->validate(['key' => 'in:site_config']);
        return $this->success($this->service->settingConfig($this->request->input('key', 'site_config')));
    }

    #[GetMapping('dictData')]
    public function dictData(): ResponseInterface
    {
        $this->validate(['key' => 'in:business_source']);
        return $this->success($this->service->dictData($this->request->input('key', 'business_source')));
    }

    #[GetMapping('version')]
    public function version(): ResponseInterface
    {
        return $this->success($this->service->version($this->request->input('app_name', '')));
    }

    #[GetMapping('versionList')]
    public function versionList(): ResponseInterface
    {
        return $this->success($this->service->versionList($this->request->input('app_name', '')));
    }

    #[GetMapping('genQrcode')]
    public function genQrcode(): ResponseInterface
    {
        return $this->response->raw($this->service->genQrcode($this->request->all()))->withHeader('Content-type', 'image/png');
    }

    #[GetMapping('getGeocoder')]
    public function getGeocoder(): ResponseInterface
    {
        return $this->success($this->service->getGeocoder($this->request->all()));
    }

    #[GetMapping('channel')]
    public function channel(): ResponseInterface
    {
        return $this->success($this->service->channel());
    }

    #[GetMapping('category')]
    public function category(): ResponseInterface
    {
        return $this->success($this->service->category());
    }

    #[GetMapping('categoryByCode')]
    public function categoryByCode(): ResponseInterface
    {
        return $this->success($this->service->categoryByCode($this->request->input('code')));
    }

    #[GetMapping('tag')]
    public function tag(): ResponseInterface
    {
        return $this->success($this->service->tag());
    }

    #[PostMapping('withdrawalStatus')]
    public function withdrawalStatus(): ResponseInterface
    {
        return $this->success($this->service->withdrawalStatus());
    }
}